<?php

defined('ByShopWWI') or exit('Access Invalid!');
class indexControl extends MobileControl{

    public function __construct() {
        parent::__construct();
      //  Tpl::output('index_sign','index');
    }

    /**
     * app首页入口
     */
    public function indexOp(){
        $model_goods = Model('goods');
        $date['gc_name']=array(array('like','茶具系列%'),array('like','银品生活%'),array('like','宗教文化%'),array('like',
            '家居摆件%'),array('like','皇家饰品%'),'or');
        $goods_class_list= Model('goods_class')->goods_list($date);

        $store_id = empty($_SESSION['store_id'])?1:$_SESSION['store_id'];
//        $goods_list_sc = $model_goods->getGoodsGcStoreRandList($goods_class_list['shopkeeper'], $store_id, 0, 3);//店长私藏
        $goods_list_ct = $model_goods->getGoodsGcStoreRandList($goods_class_list['teaSet'], $store_id);//茶具系列
        $goods_list_sl = $model_goods->getGoodsGcStoreRandList($goods_class_list['silverLife'], $store_id);//银品生活
        $goods_list_bj = $model_goods->getGoodsGcStoreRandList($goods_class_list['religCulture'], $store_id);//宗教文化
        $goods_list_bg = $model_goods->getGoodsGcStoreRandList($goods_class_list['home'], $store_id);//家居摆件
        $goods_list_cj = $model_goods->getGoodsGcStoreRandList($goods_class_list['queen'], $store_id);//皇家饰品

//        Tpl::output('goods_list_sc',$goods_list_sc);
        Tpl::output('goods_list_ct',$goods_list_ct);
        Tpl::output('goods_list_sl',$goods_list_sl);
        Tpl::output('goods_list_bj',$goods_list_bj);
        Tpl::output('goods_list_bg',$goods_list_bg);
        Tpl::output('goods_list_cj',$goods_list_cj);

        Tpl::output('goods_class_list',$goods_class_list);

        //获取公告
        $article_class = Model('cms_article_class')->getOne(array('class_name'=>'公告'));
        $condition = array();
        $condition['article_state'] = 3;
        $condition['article_class_id'] = $article_class['class_id'];
        $article_list = Model('cms_article')->getListWithClassName($condition);

        Tpl::output('article_list',$article_list);

        Tpl::showpage('index');
    }

    /**
     * 金贵银器
     */
    public function index2Op(){
        $model_goods = Model('goods');
       // $date['gc_name']=array(array('like','热销产品%'),array('like','信仰文化传承%'),array('like','馈赠礼品%'),array('like',
      //      '营造家具氛围%'),array('like','人与建筑环境的和谐%'),array('like','美食不如美器%'), 'or');
        $date['gc_name']=array(array('like','茶具系列%'),array('like','银品生活%'),array('like','宗教文化%'),array('like',
            '家居摆件%'),array('like','皇家饰品%'),'or');
        $goods_class_list= Model('goods_class')->goods_list($date);

        $store_id = empty($_SESSION['store_id'])?1:$_SESSION['store_id'];
        $goods_list_rx = $model_goods->getGoodsOnlineList(array('store_id' => $store_id ), '*', 0, 'rand()', 3);
        $goods_list_wh = $model_goods->getGoodsGcStoreRandList($goods_class_list['teaSet'], $store_id, 0, 2);
        $goods_list_kz = $model_goods->getGoodsGcStoreRandList($goods_class_list['silverLife'], $store_id, 0, 2);
        $goods_list_yz = $model_goods->getGoodsGcStoreRandList($goods_class_list['religCulture'], $store_id, 0, 2);
        $goods_list_ren = $model_goods->getGoodsGcStoreRandList($goods_class_list['home'], $store_id, 0, 2);
        $goods_list_ms = $model_goods->getGoodsGcStoreRandList($goods_class_list['queen'], $store_id, 0, 2);

        Tpl::output('goods_list_rx',$goods_list_rx);
        Tpl::output('goods_list_wh',$goods_list_wh);
        Tpl::output('goods_list_kz',$goods_list_kz);
        Tpl::output('goods_list_yz',$goods_list_yz);
        Tpl::output('goods_list_ren',$goods_list_ren);
        Tpl::output('goods_list_ms',$goods_list_ms);

        Tpl::output('goods_class_list',$goods_class_list);

        Tpl::showpage('index2');
    }

    /**
     * 消息中心
     */
    public function msg_centerOp(){
        $model_message	= Model('message');
//        $page	= new Page();
//        $page->setEachNum(10);
//        $page->setStyle('admin');
        $message_array	= $model_message->listMessage(array('from_member_id'=>'0','message_type'=>'1','to_member_id'=>$_SESSION['member_id'],'no_del_member_id'=>$_SESSION['member_id']));
        if (!empty($message_array) && is_array($message_array)){
            foreach ($message_array as $k=>$v){
                $v['message_open'] = '0';
                if (!empty($v['read_member_id'])){
                    $tmp_readid_arr = explode(',',$v['read_member_id']);
                    if (in_array($_SESSION['member_id'],$tmp_readid_arr)){
                        $v['message_open'] = '1';
                    }
                }
                $v['message_body'] = substr($v['message_body'],0,strrpos($v['message_body'],'<a href'));
                $message_array[$k]	= $v;
            }
        }
        Tpl::output('message_array',$message_array);
        Tpl::showpage('msg_center');
    }

    public function msg_detailOp(){//消息详情
        $model_message  = Model('message');
        $message_id =  intval($_GET['message_id']);

        $param = array();
        $param['message_id'] = "$message_id";
        $param['to_member_id'] = "{$_SESSION['member_id']}";
        $param['no_del_member_id'] = "{$_SESSION['member_id']}";
        $message_info = $model_message->getRowMessage($param);

        //更新为已读信息
        $tmp_readid_str = '';
        if (!empty($message_info['read_member_id'])){
            $tmp_readid_arr = explode(',',$message_info['read_member_id']);
            if (!in_array($_SESSION['member_id'],$tmp_readid_arr)){
                $tmp_readid_arr[] = $_SESSION['member_id'];
            }
            foreach ($tmp_readid_arr as $readid_k=>$readid_v){
                if ($readid_v == ''){
                    unset($tmp_readid_arr[$readid_k]);
                }
            }
            $tmp_readid_arr = array_unique ($tmp_readid_arr);//去除相同
            sort($tmp_readid_arr);//排序
            $tmp_readid_str = ",".implode(',',$tmp_readid_arr).",";
        }else {
            $tmp_readid_str = ",{$_SESSION['member_id']},";
        }
        $model_message->updateCommonMessage(array('read_member_id'=>$tmp_readid_str),array('message_id'=>"{$message_id}"));

        if (!empty($message_info)){
            $message_info['message_body'] = substr($message_info['message_body'],0,strrpos($message_info['message_body'],'<a href'));
        }
        Tpl::output('message_info',$message_info);
        Tpl::showpage('msg_detail');
    }
}
